package com.nvwa.coding.exception;

import java.io.PrintStream;
import java.io.PrintWriter;


/**
 * 将任意Throwable包装成RuntimeException
 */
public class WrappedException extends RuntimeException {

    protected Throwable origin;

    public WrappedException(Throwable origin) {
        this.origin = origin;
    }

    public Throwable getOrigin() {
        return origin;
    }

    public static void wrapThrow(Throwable origin) {
        if (origin instanceof RuntimeException) {
            throw (RuntimeException) origin;
        }
        throw new WrappedException(origin);
    }

    @Override
    public String getMessage() {return origin.getMessage();}

    @Override
    public String getLocalizedMessage() {return origin.getLocalizedMessage();}

    @Override
    public Throwable getCause() {return origin.getCause();}

    @Override
    public Throwable initCause(Throwable cause) {return origin.initCause(cause);}

    @Override
    public String toString() {return origin.toString();}

    @Override
    public void printStackTrace() {origin.printStackTrace();}

    @Override
    public void printStackTrace(PrintStream s) {origin.printStackTrace(s);}

    @Override
    public void printStackTrace(PrintWriter s) {origin.printStackTrace(s);}

    @Override
    public StackTraceElement[] getStackTrace() {return origin.getStackTrace();}

    @Override
    public void setStackTrace(StackTraceElement[] stackTrace) {origin.setStackTrace(stackTrace);}

}
